package com.example.myapplication1

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class BookAdapter(val Books: ArrayList<Book>) : RecyclerView.Adapter<BookAdapter.BookViewHolder>() {



        inner class BookViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

            val name = itemView.findViewById<TextView>(R.id.name)

            val desc = itemView.findViewById<TextView>(R.id.description)

            val img =  itemView.findViewById<ImageView>(R.id.avatar)

        }



    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BookViewHolder {

            val view = LayoutInflater.from(parent.context).inflate(R.layout.item_book,parent,false)

            val holder = BookViewHolder(view)

            return holder

        }



        override fun onBindViewHolder(holder: BookViewHolder, position: Int) {

            val book = Books[position]

            holder.name.text = book.name

            holder.desc.text = book.description

            holder.img.setImageResource(book.avatar)

        }



        override fun getItemCount(): Int {

            return Books.size

        }

    }

